package com.code.coinprice.controllers;

import com.code.coinprice.models.PushMessage;
import com.code.coinprice.services.PushService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/push")
public class PushController {

    private final PushService pushService;

    public PushController(PushService pushService) {
        this.pushService = pushService;
    }

    /**
     * 推送给所有用户
     */
    @PostMapping("/pushAll")
    public void pushToAll(@RequestBody PushMessage pushMessage) {
        pushService.pushMsgToAll(pushMessage.getPushMsg());
    }

    /**
     * 推送给指定用户
     */
    @PostMapping("/pushOne")
    public void pushMsgToOne(@RequestBody PushMessage pushMessage) {
        pushService.pushMsgToOne(pushMessage.getClientChannelId(), pushMessage.getPushMsg());
    }

}
